<template>
	<view class="hui">
		<view class="head">请选择如下通道开门</view>
		
		<view class="list_box">
			
			<view @click="set(item)" :class="['list_info',check.id==item.id?'check':'']" v-for="(item,index) in list" :key="index">
				{{item.device.name}}
			</view>
			
		</view>
		
		<view class="bitmap" v-if="emptyShow">
			<image :src="none" mode="widthFix"></image>
			<view class="gray_font fs-13">
				亲，您还没有相关门禁
			</view>
		</view>
		
		<view class="submit" @click="to">确认开门</view>
		
	</view>
</template>

<script>
	export default{
		data(){
			return{
				params:{page:1},
				check:'',
				emptyShow:false,
				none:'',
				list:[]
			}
		},
		onLoad() {
		  this.none=this.$imgUrl+'assets/img/none_order.png';	
		},
		onShow() {
			this.$needLogin(() => {
				this.getUserInfo();
				this.getList();
			}, 3, '/pages/fw/passage/door','请先登录',2);
		},
		methods:{
			getList() {
				this.params.page = 1;
				this.params.token=uni.getStorageSync('userToken');
				this.$get(this.$api.doorMj, this.params, res => {
					let data = res.data;
			
					if (!data.data.data || data.data.data.length < 1) {
						this.emptyShow = true;
					} else {
						this.emptyShow = false;
					}
			
					this.list = data.data.data;
					this.total = data.data.total;
				});
			},
			getUserInfo() {
				let token = uni.getStorageSync('userToken');
				if (!token) return;
			
				this.$get(this.$api.userInfo, {
					token: token
				}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.user = data.data;
						this.$project.common(this.user,3,2);
					}
				});
			},
			to() {
				let _ = this;
				this.$needLogin(() => {
			
			
					_.$project.common(_.user, 3);
			
					if (_.user.audit_status != 2) return;
			
					_.submit();
			
				},3,'/pages/fw/passage/door','请先登录',2);
			},
			set(e){
				this.check=e;
			},
			submit(){
			
				if(!this.check) return this.$project.toast('请选择');
			    
				this.$post(this.$api.doorOpen,{id:this.check.id},res=>{
					let data=res.data;
					if(data.code==1){
						this.$project.toast(data.msg);
						
						setTimeout(()=>{
							this.$project.toBack();
						},1000);
						
					}else{
						this.$project.toast(data.msg);
					}
				})
					
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hui{
		box-sizing:border-box;
		padding: 10rpx 0 0 0;
	}
	.head{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx 0;
		text-align: center;
		background-color: white;
		color:#7B7B7B;
		font-size: 28rpx;
	}
	.list_box{
		box-sizing: border-box;
		padding:30rpx 20rpx;
	}
	.list_info{
		width: 100%;
		background-color: white;
		box-sizing: border-box;
		padding: 20rpx 0 20rpx 50rpx;
		margin-bottom: 20rpx;
		border-radius: 15rpx;
		font-size: 30rpx;
		box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.1);
	}
	.check{
		background-color:#FDB441;
		color: white;
	}
	.submit{
		width:85%;
		position: fixed;
		bottom: 45rpx;
		left:7.5%;
		background-color:#e34b0f;
		color: white;
		border-radius: 45rpx;
		text-align: center;
		box-sizing: border-box;
		padding:20rpx 0;
		font-size: 28rpx;
	}
	
	.bitmap {
		margin-top: 15vh;
		text-align: center;
		image{
			width: 60%;
		}
	}
	
</style>